package com.cskaoyan.controller;

import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.po.MarketUser;
import com.cskaoyan.bean.vo.WxSearchHelperVo;
import com.cskaoyan.service.WxSearchService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.io.Serializable;

/**
 * @author Trellis
 * @since 2022/09/08 21:09
 */
@RestController
@RequestMapping("wx/search")
public class WxSearchController {

    @Autowired
    WxSearchService wxSearchService;

    @RequestMapping("index")
    public BaseRespVo index(){
        Session session = SecurityUtils.getSubject().getSession();
        MarketUser info = (MarketUser) session.getAttribute("info");
        Integer userId = info.getId();
        BaseRespVo baseRespVo = wxSearchService.selectAll(userId);
        return baseRespVo;
    }

    @RequestMapping("helper")
    public WxSearchHelperVo helper(String keyword) {
        Session session = SecurityUtils.getSubject().getSession();
        MarketUser info = (MarketUser) session.getAttribute("info");
        Integer id = info.getId();
        WxSearchHelperVo wxSearchHelperVo = wxSearchService.selectByKeyword(keyword,id);
        return wxSearchHelperVo;
    }

    @RequestMapping("clearhistory")
    public BaseRespVo clearhistory() {
        Session session = SecurityUtils.getSubject().getSession();
        MarketUser info = (MarketUser) session.getAttribute("info");
        Integer id = info.getId();
        BaseRespVo clearhistory = wxSearchService.clearhistory(id);
        return clearhistory;
    }
}
